<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>申请书编辑</title>
<script type="text/javascript" src="${res}/js/jquery/jquery.form.js"></script>
<script type="text/javascript"
	src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript"
	src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript"
	src="${res}/js/keyword/keywordtips.js"></script>	
<script type="text/javascript"
	src="${res_app}/js/app/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript"
    src="${res_app}/js/app/base.js"></script>
    
<style>
	textarea{overflow:auto;}
</style>

<script type="text/javascript">
$(function(){
	queryflex();
});
/**
 * 申请书提交方法
 */


var ctxpath = "${ctx}";
var prcWin = new progressWin("${res}");//初始化遮罩层
/**
 * 页面初始化方法 所有的都定义在里面
 */
$(document).ready (function() {
	$("#wbox1").click(function() {
		check("check");
	});
	
	$("#wbox2").click(function() {
		
		check("check");
		
	});
	
	initControl();
	
	$("table.t_css").not("[id='finances']").not("[id='checkbox_table_']").not("[id='budgetsMsg2']").not("[id='basicInfo']").each(function(){  
		$(this).find("tr:even").addClass("li_1");
		$(this).find("tr:odd").addClass("li_2");
	});
	$("table").addClass("table01");
	$("#checkbox_table_").removeClass("table01");
	$("#feaReport_upload").removeClass("table01");
    $('div').find("[id^='checkbox_dyn_']").find("tr").removeClass("li_1").removeClass("li_2");
    $('div').find("[id^='checkbox_dyn_']").find("td").css("border",'0px solid');
	
	window.setInterval("checkPdfStatus()", "10000");//检验申请书的pdf
});

$(document).ready(function() {
	/* fileInit("feaReport_upload","DOC,DOCX,PDF,WPS"); */
	/* fileInit("prpContent_upload","PDF,DOC,DOCX,WPS",null,"{'PDF':'51200','DOCX':'51200','DOC':'51200','WPS':'51200'}"); */
	fileInit("feaReport_upload","PDF");
	fileInit("prpContent_upload","PDF",null,"{'PDF':'20480'}");
	
	//fileInitAttach("attachAdd", "JPG,PDF", null, 20, "{'JPG':'3072','PDF':'3072'}");
	$("#prpContent_upload").find(".file").hide();//隐藏文本框
});


$(document).ready(function() {
	$("#org").attr("disabled","true");
	initDepartForComplete("org");
	 initControl();
});

/**
 * 申报日期默认为当前日期
 */
 $(document).ready(function() {

		var nowDate = '${sercverSysDate1}';
	    if($("#apply_date_curr").val()==""){
		   $("#apply_date_curr").val(nowDate);
	    }

	}); 

/**
 * 填写检查
 */
function check(type){
	setTotalAmt();
	
	validate($("#pro_info"),"项目基本情况"); 
	
	checkWord();
	
	checkCan();
	
	validate($("#pro_info2"),"项目基本情况-->项目负责人信息"); 
	
	//validateByTabRow($("#cooperativeunit"),"合作研究单位信息");
	
	validate($("#fragment-tab3"),"经费预算");
	
	check_goal();
	/* 
	if($("#total_each_0").val()!=$("#total_fund_18").val()){
		irisValaddMsg("项目经费情况-->资金概算-->资金来源概算-->省财政拨款来源合计应等于资金支出概算-->省财政拨款支出总额");
	} */
	
	//validateByTabRow($("#cooperativeunit"),"合作研究单位信息",1);
	
	
	validate($("#tblresume"),"项目人员情况"); 
	
	validate($("#feaReport_upload"),"申请书正文"); 
	
	validate($("#fragment-tab6"),"预期目标"); 
	
	numAddCheck('performance_1','performance1_forcompare');
	
	numAddCheck('performance_5','performance5_forcompare');
	
	numAddCheck('performance_30','performance30_forcompare');
	
	numAddCheck('performance_48','performance48_forcompare');
	
	numAddCheck('performance_54','performance54_forcompare');
	
	/* validate($("#performances1"),"项目绩效目标");  */
	
	irisJqValEmpty($("#fragment-tab8"),"申请人科研业绩统计表-->请填写完整");
	
	
	//validatePsnAge();
	
	//var file_code= $("input[name$='content[01]/file_code']").val();
	
	prp_attach(); 
	if(!valResult()){
		irisValShowMsg($("#wbox1"));
		return false;
	}
	if(type=="check"){
		showBox($("#wbox1"), "300px", "200px", "检查通过","1:所有检查全部合格");
	}
	return true;
}
function setTotalAmt(){
	$('#request_amt').val($("#request_money").html().trim());
}


function checkCan(){
	if(validatePsnAge()){
	
	var grant_Code = $("#grantCode").val();
	
	var level_no = $("#level_no").val();
	
	var file_code= $("input[name$='content[01]/file_code']").val();
	
	var degree_name = $("span[name$='degree_name']").html().trim();
	degree_name = degree_name.trim();
	if(grant_Code==4759){
		if(level_no == 1 || level_no == 2 || degree_name == "博士"){
			//validatePsnAge();
			//irisValaddMsg("请上传附件材料-高级专业技术职务（职称）证书或博士学位证书，2者中上传专业技术职务（职称）证书或博士学位证书");
			return;
		}else{
			//validatePsnAge();
			irisValaddMsg("您不具有博士学位或高级专业技术职称，不符合申报条件");
			return;
		}
	}
	}
}
/* 关键字5个字限制 */
function checkWord(){
	var keyword = $.trim($("#keyword").val());
	if(keyword != ""){
		if(keyword.indexOf(";")!=-1){
			irisValaddMsg("项目基本情况-->项目内容摘要-->关键字请用中文分号隔开");
		}else{
		var wordArray = keyword.split("；");
		var wordArray1 = keyword.split("；；");
		var wordArray2=	keyword.charAt(keyword.length-1);
		if(wordArray2=="；"){
			wordArray.length-=1;
		}
		if(wordArray.length < 1 || wordArray.length >5||wordArray1.length>1){
			irisValaddMsg("项目基本情况-->关键词：（用中文分号分开，最多5个）");
			}
		}
	 }
}


/*时间比对 */
function validatePsnAge() {
	/* debugger; */
	var statyear = $("#statyear").html();
    var str1 = statyear+"-01-01";
    var str2 =  $("#fzbirthday").html();
	var grant_Code = $("#grantCode").val();
	if(str2==""){
		irisValaddMsg("在填写申报书之前，请完整填写个人信息中的出生日期");
		return ;
	}
    if (str1 == "" || str2 == "")
        return ;
    var year = calFullYear(str2,str1,locale);
    
  //  alert(secondDate-firstDate);
	  if(grant_Code == 4759){
	    if (year > 40) {
	    	irisValaddMsg("申报人年龄大于40周岁不允许申报当前项目");
	    	return false;
	    }else{
	    	return true;
	    }
	  }
}
/*经费检验  */
function check_goal(){
	var get_money = parseFloat($("#total_each_0").val());
	if (!$.isNumeric(get_money)){
		get_money = "0.00";}
	var indirect_money = parseFloat($("#total_fund_15").val());
	if (!$.isNumeric(indirect_money)){
		indirect_money = "0.00";}
	var direct_money = parseFloat($("#total_fund_0").val());
	if (!$.isNumeric(direct_money)){
		direct_money = "0.00";}
	var equipment_money =  parseFloat($("#total_fund_2").val());
	if (!$.isNumeric(equipment_money)){
		equipment_money = "0.00";}
	var left_money = parseFloat(direct_money-equipment_money);
	if (!$.isNumeric(left_money)){
		left_money = "0.00";}
	 if(get_money<100){
		if(indirect_money>left_money*0.3){
			irisValaddMsg("经费情况-->资金概算-->省财政拨款-->概算金额小于100万元时，资金支出概算-->其中：省财政拨款间接费用不能超过直接费用减去购置设备费后的30%");
		}
	}
	if(get_money<300 && get_money>=100){
		if(indirect_money>left_money*0.25){
			irisValaddMsg("经费情况-->资金概算-->省财政拨款-->概算金额小于300万元并且大于100万元(包含100万元)时，其中：省财政拨款间接费用不能超过直接费用减去购置设备费后的25%");
		}
	}
	if(get_money<500 && get_money>=300){
		if(indirect_money>left_money*0.2){
			irisValaddMsg("经费情况-->资金概算-->省财政拨款-->概算金额小于500万元并且大于300万元(包含300万元)时，其中：省财政拨款间接费用不能超过直接费用减去购置设备费后的20%");
		}
	}
	if(get_money>=500){
		if(indirect_money>left_money*0.15){
			irisValaddMsg("经费情况-->资金概算-->省财政拨款-->概算金额大于500万元(包含500万元)时，其中：省财政拨款间接费用不能超过直接费用减去购置设备费后的15%");
		}
	} 

} 

/* 输入然后，比对后面的 */
function numAddCheck(totalNum,totalHidden) {
	/* var indexs = countStr.split(",");
	var moneyAll = 0;
	var money = 0;
	for ( var i = 0; i < indexs.length; i++) {
		money= $("#"+indexs[i]).val().trim();
		moneyAll = parseInt(money) + parseInt(moneyAll);
	} */
	var totalNums = $("#"+totalNum).val();
	var totalHiddens = $("#"+totalHidden).val();
	
	if(totalHidden == 0 || totalHidden == ""){
		return ;
	}
	if(totalNums == "" && totalHiddens == ""){
		return ;
	}
	if(totalNums == "" && totalHiddens == 0){
		return ;
	}
	if(parseInt(totalNums) < parseInt(totalHiddens)){
		$(totalNum).attr("lable");
		var msg = "项目绩效目标-->"+$("#"+totalNum).attr("label")+"必须大于等于"+$("#"+totalHidden).attr("label");
		irisValaddMsg(msg);
	}
}

</script>
<style>
	textarea{overflow:   auto;}
</style>
</head>
<body>

	<c:set var="xmlstr" value="${xmlData}" scope="request"/>
	<x:parse xml="${xmlstr}" var="xmlData"  scope="request" />
	<input type="hidden" id="childDiv" class="thickbox"/>
	<input type="hidden" id="filePath" value="${ctx}/file/ajax-filedownload?fileCode=" />
	<input type="hidden" id="menuId" value="${param.menuId}" />
	<input type="hidden" id="sysDate" value="${sercverSysDate}" />
	<div id="showMessage"></div>
	<div id="content">
		<cpt:helpTips key="prpedit" id="prpEditTips"></cpt:helpTips>
		<div class="clear_h15"></div>
		<div class="word_box" id="mainDiv">
		    
		   <!-- 公用的配置界面 ：保存、提交等button-->
			<jsp:include page="./prpeditmain_public_last_zrjj.jsp"><jsp:param value="${xmlstr}" name="xmlstr" /></jsp:include>
		    
			<div class="bar_b">
				<input type="hidden" id="pdfStatus" value="${pdfStatus}" />
				<span class="right">版本号：<span name="proposal/prp_version" id="prp_version"><x:out select="$xmlData/data/proposal/prp_version" /></span></span>
			</div>
			<form method="post" id="mainForm">
				<input type="hidden" value="${grantCode}" id="grantCode"
					name="grantCode"> 
				<input type="hidden" value="${posCode}" id="posCode" name="posCode"> 
				<input type="hidden" value="<iris:des3 code="${posCode}"></iris:des3>" id="posCodeDes" name="posCodeDes">
				<input type="hidden" value="<iris:des3 code="${fbl.pdfCode}"></iris:des3>" id="pdfCodeDes" name="pdfCodeDes">  
				<input type="hidden" value="${xmlData}" id="xmlData" name="xmlData">
				<input type="hidden" value="${fbl.pdfCode}" id="pdfCode" name="pdfCode"> 
				<input type="hidden" value="${flag_shizhi}" id="flag_shizhi" name="proposal/flag_shizhi"> 
				<input type="hidden" value="<x:out select="$xmlData/data/proposal/level_no" />" id="level_no" name="proposal/level_no"> 
			</form>
				<div class="word_title">
					<c:set var="statYear">${statYear}</c:set>
					<c:if test="${empty statYear}">
						<c:set var="statYear"><x:out select="$xmlData/data/proposal/stat_year" /></c:set>
					</c:if>
					<c:set var="pro_start_date">${pro_start_date}</c:set>
					<c:if test="${empty pro_start_date}">
						<c:set var="pro_start_date"><x:out select="$xmlData/data/proposal/start_date" /></c:set>
					</c:if>
					<c:set var="pro_end_date">${pro_end_date}</c:set>
					<c:if test="${empty pro_end_date}">
						<c:set var="pro_end_date"><x:out select="$xmlData/data/proposal/end_date" /></c:set>
					</c:if>
					<input type="hidden" name="proposal/stat_year" value="${statYear}">
					<input type="hidden" name="proposal/pro_start_date" value="${pro_start_date}">
					<input type="hidden" name="proposal/pro_end_date" value="${pro_end_date}">
					<span name="proposal/grant_name" ><x:out select="$xmlData/data/proposal/sub_grant_name" /></span>-项目申请书 (<span name="proposal/stat_year" id ="statyear">${statYear}</span>年)<%-- <br/><span name="proposal/sub_grant_name" >(<x:out select="$xmlData/data/proposal/sub_grant_name" />)</span> --%>


					<input type="hidden" name="proposal/request_money"  value="<x:out select="$xmlData/data/proposal/request_money" />"  />
					<input type="hidden" name="proposal/manage_category" value="<x:out select="$xmlData/data/proposal/manage_category" />" />
					<input type="hidden" name="proposal/sub_grant_name" value="<x:out select="$xmlData/data/proposal/sub_grant_name" />" />
					<input type="hidden" name="proposal/grant_code" value="<x:out select="$xmlData/data/proposal/grant_code" />" />  <input type="hidden" name="proposal/psn_code" value="<x:out select="$xmlData/data/proposal/psn_code" />" />
					<input type="hidden" id="grant_no" name="proposal/grant_no" value="<x:out select="$xmlData/data/proposal/grant_no" />" />							
					<input type="hidden" name="proposal/sub_grant_code" value="<x:out select="$xmlData/data/proposal/sub_grant_code" />" />
					<input name="proposal/register_area_code" type="hidden" value="<x:out select="$xmlData/data/organizations/organization[@submit_org='1']/area_value" />" />
		            <input name="proposal/register_area_name" type="hidden" value="<x:out select="$xmlData/data/organizations/organization[@submit_org='1']/area_name" />" />
					<input type="hidden" id="sub_grant_no" name="proposal/sub_grant_no" value="<x:out select="$xmlData/data/proposal/sub_grant_no" />" />
					<input type="hidden" name="proposal/help_grant_code" value="<x:out select="$xmlData/data/proposal/help_grant_code" />" />
					<input type="hidden" id="help_grant_no" name="proposal/help_grant_no" value="<x:out select="$xmlData/data/proposal/help_grant_no" />" />
					<c:set var="formCode"><x:out select="$xmlData/data/proposal/form_code" /></c:set>
					<c:set var="nature_value"><x:out select="$xmlData/data/organizations/organization[@submit_org='1']/nature_value" /> </c:set>
					<c:if test="${empty formCode}"><c:set var="formCode" value="${param.formCode}"></c:set></c:if>
					<input type="hidden" name="proposal/form_code" value="${formCode}" />
				    <input type="hidden" name="proposal/request_amt" 	id="request_amt" value="<x:out select="$xmlData/data/proposal/request_amt"/>">
					<input type="hidden" name="proposal/year" value="${year}" />
					<input type="hidden" name="organizations/organization/nature_value" value="<x:out select="$xmlData/data/organizations/organization[@submit_org='1']/nature_value" />"/>
					<input type="hidden" name="organization/whether_is_gaoxin_value" value="<x:out select="$xmlData/data/organization/whether_is_gaoxin_value" />"/>
					<input type="hidden" name="organization/whether_industrial_base_value" value="<x:out select="$xmlData/data/organization/whether_industrial_base_value" />"/>
					<input type="hidden" name="organization/whether_is_province_value" value="<x:out select="$xmlData/data/organization/whether_is_province_value" />"/>
					<!-- 申请日期 -->
					<input type="hidden" id="submit_date1" name="proposal/submit_date" value="<x:out select="$xmlData/data/proposal/submit_date" />" />			
				 <!-- 公用的配置界面 -->
				    <jsp:include page="./prpeditmain_public.jsp"><jsp:param value="${xmlstr}" name="xmlstr" /></jsp:include>
				</div>
				<div id="tabnav">
					<ul>
						<li class="down" id="tab1" onclick="changeTab(this.id)">
						    <a href="###"><span>单位基本情况</span></a>
						</li>
						
						<li  id="tab2" onclick="changeTab(this.id)">
						    <a href="###"><span>项目基本情况</span></a>
						</li>
						
						<li id="tab3" onclick="changeTab(this.id)" >
						    <a href="###"><span>经费预算</span></a>
						</li>
						
						<li id="tab4" onclick="changeTab(this.id)">
						    <a href="###"><span>项目人员情况</span></a>
						</li>
							
						<li id="tab5" onclick="changeTab(this.id)" >
						    <a href="###"><span>申请书正文</span></a>
						</li>
						
						<li id="tab6" onclick="changeTab(this.id)" >
						    <a href="###"><span>预期目标</span></a>
						</li>
						
						<li id="tab7" onclick="changeTab(this.id)" >
						    <a href="###"><span>项目绩效目标</span></a>
						</li>
					</ul>
				</div>	
				<div id="tabnav">
					<ul>
						<li id="tab8" onclick="changeTab(this.id)" >
						    <a href="###"><span>申请人科研业绩统计表</span></a>
						</li>
						<li id="tab9" onclick="changeTab(this.id)" >
						    <a href="###"><span>需提交的材料</span></a>
						</li>
					</ul>	
				</div>
				<!-- 单位基本情况 -->
 		    	<div class="tab_box" id="fragment-tab1" >
					<jsp:include page="../org/prporg_baseinfo_enterprise_new.jsp">
						<jsp:param value="1、单位基本信息" name="title" />
						<jsp:param value="2、单位人员情况" name="title2" />
						<jsp:param value="3、单位财务状况" name="title3" />
						<jsp:param value="4、企业开展产学研合作情况" name="title4" />
						<jsp:param value="5、主营业务产品" name="title5" />
						<jsp:param value="6、知识产权情况" name="title6" />
						<jsp:param value="${xmlstr}" name="xmlstr" />
						<jsp:param value="${statYear}" name="statyear" />
						<jsp:param value="${year}" name="curryear" />
					</jsp:include>
				</div>
				
				<!-- 项目基本情况 -->
				<div class="tab_box" id="fragment-tab2" style="display: none">
					<jsp:include page="../goal/prpgoaledit_jcjj_2018.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
						<jsp:param value="${pro_start_date}" name="pro_start_date" />
						<jsp:param value="${pro_end_date}" name="pro_end_date" />
					</jsp:include>
				</div>
				
					<!-- 项目经费情况-->
				<div class="tab_box" id="fragment-tab3" style="display: none">
					<jsp:include page="../fund/prpfundedit_jcjj_2018.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					   <jsp:param value="${statYear}" name="statyear" />
						<jsp:param value="经费预算" name="title" />
						<jsp:param value="（单位：万元，保留两位小数）" name="unit"/>
					</jsp:include>
				</div>
				
					<!-- 项目人员情况-->
				<div class="tab_box" id="fragment-tab4" style="display: none">
					<jsp:include page="../psn/prpzhpsn_jcjj_2018.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
						<jsp:param value="项目人员情况 " name="title" />
					</jsp:include>
				</div>
				
				
				<!-- 报告正文申请书正文.docx-->
				<div class="tab_box" id="fragment-tab5" style="display: none">
					<jsp:include page="../content/prpContentEdit_jcjj_2018.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
						<jsp:param value="申请书正文" name="title" />
					</jsp:include>
				</div>
				
				<!-- 预期目标 -->
				<div class="tab_box" id="fragment-tab6" style="display: none">
					<jsp:include page="../goal/prpgoaledit_jcjjgoal_2018.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div>
				
				<!-- 项目绩效目标-->
				<div class="tab_box" id="fragment-tab7" style="display: none">
					<jsp:include page="../performance/prpperformanceedit_jcjj_2018.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div>
				
				<!-- 申请人科研业绩统计表-->
				<div class="tab_box" id="fragment-tab8" style="display: none">
					<jsp:include page="../psnstudy/prpperformanceedit_jcjj_2018.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
				</div>
				
				<!-- 需提交的材料 -->
				<div class="tab_box" id="fragment-tab9" style="display: none">
					<jsp:include page="../attach/prpAttachEdit_jcjj.jsp">
						<jsp:param value="${xmlstr}" name="xmlstr" />
					</jsp:include>
					<p style="font-size: 13px"><strong>备注：</strong></p>
					<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.递交纸质材料时，提供系统打印的申请书纸质文件，一式二份，签字盖章后报省政务服务中心</p>
					<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.递交纸质材料时，基奖处校验以上附件材料</p>
				</div>
				
			<!-- 公用的配置界面 ：保存、提交等button -->
			<jsp:include page="./prpeditmain_public_first_zrjj.jsp"><jsp:param value="${xmlstr}" name="xmlstr" /></jsp:include>
		</div>
		<div class="clear_h15"></div>
	</div>
</body>

</html>